home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / fcntl.c < prev    next >
C/C++ Source or Header  |  1996-01-04  |  832b  |  44 lines

  1. #include "amiga.h"
  2. #include "files.h"
  3. #include <fcntl.h>
  4. #include <sys/filio.h>
  5. #include <stdarg.h>
  6.  
  7. /* Flags that can be changed with fcntl */
  8. #define FCNTL_FLAGS (O_NDELAY | O_APPEND)
  9.  
  10. int fcntl(int fd, int cmd,...)
  11. {
  12.     struct fileinfo *fi;
  13.     va_list args;
  14.     int arg;
  15.  
  16.     __chkabort();
  17.     va_start(args, cmd);
  18.     arg = va_arg(args, int);
  19.     va_end(args);
  20.  
  21.     if (fi = _find_fd(fd)) {
  22.     switch (cmd) {
  23.         default:
  24.         errno = EINVAL;
  25.         break;
  26.         case F_GETFL:
  27.         return fi->flags & FCNTL_FLAGS;
  28.         case F_SETFL:
  29.         {
  30.             int oldfl = fi->flags;
  31.  
  32.             fi->flags = (fi->flags & ~FCNTL_FLAGS) | (arg & FCNTL_FLAGS);
  33.             if ((oldfl & O_NDELAY) != (fi->flags & O_NDELAY)) {
  34.             int ndelay = fi->flags & O_NDELAY;
  35.  
  36.             return fi->ioctl(fi->userinfo, FIONBIO, &ndelay);
  37.             }
  38.             return 0;
  39.         }
  40.     }
  41.     }
  42.     return -1;
  43. }
  44.